<?php
include "../../../lib/list.php";
if($mode == 'search'){
$barcode = $_POST['barcode'];
$name = $_POST['name'];
$namegana = $_POST['namegana'];
$minprice = $_POST['minprice'];
$maxprice = $_POST['maxprice'];
$bigcategory = $_POST['bigcategory'];
$middlecategory = $_POST['middlecategory'];
$smallcategory = $_POST['smallcategory'];
$bumun = $_POST['bumun'];
$buyer = $_POST['buyer'];

if($barcode){
	$sear_char .= " and barcode like '%$barcode%' ";
}
if($name){
	$sear_char .= " and productname like '%$name%' ";
}
if($namegana){
	$sear_char .= " and productnamegana like '%$namegana%' ";
}
if($bumun){
	$sear_char .= " and bumun_no = '$bumun' ";
}
if($buyer){
	$sear_char .= " and buyer = '$buyer' ";
}
if($bigcategory!='-1'&&$bigcategory){
	$sear_char .= " and b_no = $bigcategory ";
}
if($middlecategory!='-1'&&$middlecategory){
	$sear_char .= " and m_no = $middlecategory ";
}
if($smallcategory!='-1'&&$smallcategory){
	$sear_char .= " and s_no = $smallcategory ";
}
if($minprice){
	$sear_char .= " AND  `price1` >=$minprice";
}
if($maxprice){
	$sear_char .= " AND  `price1` <=$maxprice";
}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<link rel="stylesheet" href="../../../css/list.css" type="text/css"></link>
<link rel="stylesheet" href="../../../css/table.blue.sorter.css" type="text/css" media="print, projection, screen"></link>
<link rel="stylesheet" href="../../../css/jquery.tablesorter.pager.css"	type="text/css" media="print, projection, screen"></link>
<script type="text/javascript" src="../../../js/jquery-1.2.6.js"></script>
<script type="text/javascript" src="../../../js/list.js"></script>
<script type="text/javascript">
	function page_move(page){
			document.view.mode.value = 'search';
			document.view.page.value = page;
			document.view.target = 'iframe';
			document.view.action = 'iframe.php';
			document.view.method = 'post';
			document.view.submit();
		}
	</script>
</head>
<body style="padding:0;margin:0;">
	<div style="width: 1024px; padding: 0px;">
			<form name="view" method="post" action="iframe.php" id="view">
	
			<input type="hidden" name="mode" value=""/>
			<input type="hidden" name="page" value=""/>
			<input type="hidden" name="name" value="<?=$name?>"/>
			<input type="hidden" name="namegana" value="<?=$namegana?>"/>
			<input type="hidden" name="minprice" value="<?=$minprice?>"/>
			<input type="hidden" name="maxprice" value="<?=$maxprice?>"/>
			<input type="hidden" name="bigcategory" value="<?=$bigcategory?>"/>
			<input type="hidden" name="middlecategory" value="<?=$middlecategory?>"/>
			<input type="hidden" name="smallcategory" value="<?=$smallcategory?>"/>
			<input type="hidden" name="buyer" value="<?=$buyer?>"/>
			<input type="hidden" name="bumun_no" value="<?=$bumun_no?>"/>
			
			<table cellspacing="1" class="tablesorter">
				<thead>
					<tr>
						<th width="10px"><input
							onclick="if (this.checked) all_checked(true); else all_checked(false);"
							type=checkbox tabindex=1 name=chk_head />
						</th>
						<th>no</th>
						<th>상품 명</th>
						<th>바코드</th>
						<th>가격</th>
						<th>구매처</th>
						<th>부문</th>
						<th>레지</th>
						<th>재고</th>
						<th>마이너스키</th>
					</tr>

				</thead>
				<tbody>
						<?php
						$page=$_POST['page'];
												
						$sql = "select * from uatp_product where 1 $sear_char order by no DESC ";
						$total = DBnumrows($sql);
						
						$scale=10; //10개만 출력하기
						if ($page == ''){
							$page=1;
						}
						
						$cpage = intval($page);//현재 페이지
						$totalpage = intval($total/$scale); //전체 페이지 갯수
						if ($totalpage*$scale != $total)
						$totalpage = $totalpage + 1;
						
						if ($cpage ==1) {
							$cline = 0 ;
						} else {
							$cline = ($cpage*$scale) - $scale ;
						}
						
						$limit=$cline+$scale;
						
						if ($limit >= $total)
						$limit=$total;
						
						$scale1 = $limit - $cline;
						
						
						$query = "select * from uatp_product where 1 $sear_char order by no DESC LIMIT $cline, $scale1";
						$result = DBquery($query);
						
						for($i=1; $list = mysql_fetch_array($result); $i++){
							$bunho = $total - ( $i + $cline) + 1;
							
							if($list['pos']!=0){
								$pos = '<font color=#0078a5>사용함</font>';
							}else{$pos = '사용안함';}
							if($list['stock']!=0){
								$stock = '<font color=#0078a5>사용함</font>';
							}else{$stock = '사용안함';
							}if($list['minus']!=0){
								$minus = '<font color=#0078a5>사용함</font>';
							}else{$minus = '사용안함';}
							?>
							<tr onclick="javascript:chk(<?=$list[no]?>)">
								<td><input type=checkbox name=chk_no[]
									value="<?=$list['no']?>" onclick="javascript:chk(<?=$list['no']?>)"></input></td>
								<td align="center" width="30px"><?=$bunho?></td>
								<td><b><?=$list['productname']?></b></td>
								<td><?=$list['barcode']?></td>
								<td><?=$list['price1']?></td>
								<td><?
								$qry = "SELECT * FROM uatp_buyer WHERE no = $list[buyer]";
								$buyer = DBarray($qry);
								echo $buyer['name'];
								?></td>
								<td><?
								$qry = "SELECT * FROM uatp_bumun WHERE no = $list[bumun_no]";
								$bumun = DBarray($qry);
								echo $bumun['name'];
								?></td>
								<td><?=$pos?></td>
								<td><?=$stock?></td>
								<td><?=$minus?></td>
							</tr>
<?php 
}
	mysql_free_result($result);
?>
			</tbody>
			</table><center>
<?php 	
page_avg($totalpage,$cpage);
?></center>
		</form>
	</div>
</body>
</html>